package com.demo.dao;

import com.demo.entity.Student;
import com.demo.entity.Teacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TeacherMapper {
    @Delete({
        "delete from teacher",
        "where tid = #{tid,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String tid);

    @Insert({
        "insert into teacher (tid, tname, ",
        "tpwd, tmajor_id, ",
        "tsuiplus)",
        "values (#{tid,jdbcType=VARCHAR}, #{tname,jdbcType=VARCHAR}, ",
        "#{tpwd,jdbcType=VARCHAR}, #{tmajorId,jdbcType=VARCHAR}, ",
        "#{tsuiplus,jdbcType=INTEGER})"
    })
    int insert(Teacher record);

    int insertSelective(Teacher record);

    @Select({
        "select",
        "tid, tname, tpwd, tmajor_id, tsuiplus",
        "from teacher",
        "where tid = #{tid,jdbcType=VARCHAR}"
    })
    @ResultMap("BaseResultMap")
    Teacher selectByPrimaryKey(String tid);

    int updateByPrimaryKeySelective(Teacher record);

    @Update({
        "update teacher",
        "set tname = #{tname,jdbcType=VARCHAR},",
          "tpwd = #{tpwd,jdbcType=VARCHAR},",
          "tmajor_id = #{tmajorId,jdbcType=VARCHAR},",
          "tsuiplus = #{tsuiplus,jdbcType=INTEGER}",
        "where tid = #{tid,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(Teacher record);

    @Select({
            "select",
            "*",
            "from student",
            "where tid = #{0} and tpwd=#{1}"
    })
    @ResultMap("BaseResultMap")
    Teacher logincheck(String mname, String pwd);

    @Select({
            "select",
            "*",
            "from teacher inner join major on teacher.tmajor_id=major.cmajor_id"
    })
    @ResultMap("BaseResultMap")
    List<Teacher> selectAllWithMajor();

    @Select({
            "select",
            "*",
            "from teacher inner join major on teacher.tmajor_id=major.cmajor_id",
            "where major.college=#{0}"
    })
    @ResultMap("BaseResultMap")
    List<Teacher> selectteaWithMajor(String college);

    @Select({
            "select",
            "*",
            "from teacher inner join major on teacher.tmajor_id=major.cmajor_id",
            "where tid=#{0}"
    })
    @ResultMap("BaseResultMap")
    Teacher selectStuWithMajor(String id);

    @Select({
            "select",
            "*",
            "from teacher",
            "left  join major on teacher.tmajor_id=major.cmajor_id",
            "left  join student on student.steacherid=teacher.tid ",
            "where major.college=#{0}"
    })
    @ResultMap("BaseResultMap")
    List<Teacher> selectfinishWithDesire(String college);


    @Select({
            "select",
            "*",
            "from teacher",
            "left  join major on teacher.tmajor_id=major.cmajor_id",
            "left  join student on student.steacherid=teacher.tid "

    })
    @ResultMap("BaseResultMap")
    List<Teacher> selectAllfinishWithDesire();
}